package com.yami.shop.live.multishop.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.live.common.model.LiveRoomBack;
import com.yami.shop.live.common.service.LiveRoomBackService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lhd
 * @date 2020-08-12 10:04:53
 */
@RestController
@RequestMapping("/live/liveRoomBack")
@Tag(name = "商家端直播间回放接口")
public class LiveRoomBackController {

    @Autowired
    private LiveRoomBackService liveRoomBackService;

    @GetMapping("/page")
    @Operation(summary =  "分页查找直播间回放信息")
    public ServerResponseEntity<IPage<LiveRoomBack>> getLiveRoomBackPage(PageParam<LiveRoomBack> page,@ParameterObject LiveRoomBack liveRoomBack) {
        return ServerResponseEntity.success(liveRoomBackService.page(page, new LambdaQueryWrapper<LiveRoomBack>()));
    }

    @GetMapping("/info/{backId}")
    @Operation(summary =  "通过id查询直播间回放信息")
    @Parameter(name = "backId", description = "直播间回放id", required = true)
    public ServerResponseEntity<LiveRoomBack> getById(@PathVariable("backId") Long backId) {
        return ServerResponseEntity.success(liveRoomBackService.getById(backId));
    }

    @PostMapping
    @PreAuthorize("@pms.hasPermission('live:liveRoomBack:save')")
    @Operation(summary =  "新增直播间回放信息")
    public ServerResponseEntity<Boolean> save(@RequestBody @Valid LiveRoomBack liveRoomBack) {
        return ServerResponseEntity.success(liveRoomBackService.save(liveRoomBack));
    }

    @PutMapping
    @PreAuthorize("@pms.hasPermission('live:liveRoomBack:update')")
    @Operation(summary =  "修改直播间回放信息")
    public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid LiveRoomBack liveRoomBack) {
        return ServerResponseEntity.success(liveRoomBackService.updateById(liveRoomBack));
    }

    @DeleteMapping("/{backId}")
    @PreAuthorize("@pms.hasPermission('live:liveRoomBack:delete')")
    @Operation(summary =  "通过id删除直播间回放信息")
    @Parameter(name = "backId", description = "直播间回放id", required = true)
    public ServerResponseEntity<Boolean> removeById(@PathVariable Long backId) {
        return ServerResponseEntity.success(liveRoomBackService.removeById(backId));
    }
}
